"""
收银台相关模型
"""

from jlpay.model.base import OrgBaseReq, BaseResponse


class OrderQueryRequest(OrgBaseReq):
    """订单查询请求"""
    
    API_PREFIX = "/open/cashier/trans/trade"
    API_URI = "/query"
    
    def __init__(self):
        """初始化订单查询请求"""
        super().__init__()
        self.out_trade_no = None
        self.trade_no = None
    
    def set_merch_no(self, merch_no):
        """
        设置商户号
        
        Args:
            merch_no: 商户号
            
        Returns:
            OrderQueryRequest实例
        """
        self.merch_no = merch_no
        return self
    
    def set_out_trade_no(self, out_trade_no):
        """
        设置外部交易号
        
        Args:
            out_trade_no: 外部交易号
            
        Returns:
            OrderQueryRequest实例
        """
        self.out_trade_no = out_trade_no
        return self
    
    def set_trade_no(self, trade_no):
        """
        设置交易号
        
        Args:
            trade_no: 交易号
            
        Returns:
            OrderQueryRequest实例
        """
        self.trade_no = trade_no
        return self


class OrderQueryResponse(BaseResponse):
    """订单查询响应"""
    
    def __init__(self, response_dict=None):
        """
        初始化订单查询响应
        
        Args:
            response_dict: 响应字典
        """
        super().__init__(response_dict)
        self.status = None
        self.merch_no = None
        self.transaction_id = None
        self.out_trade_no = None
        self.chn_transaction_id = None
        self.total_amount = None
        self.order_time = None
        self.trans_time = None
        self.pay_time = None
        self.term_no = None
        self.device_no = None
        self.remark = None
        self.pay_type = None
        self.openid = None
        self.final_amount = None
        
        if response_dict:
            self.status = response_dict.get('status')
            self.merch_no = response_dict.get('merch_no')
            self.transaction_id = response_dict.get('transaction_id')
            self.out_trade_no = response_dict.get('out_trade_no')
            self.chn_transaction_id = response_dict.get('chn_transaction_id')
            self.total_amount = response_dict.get('total_amount')
            self.order_time = response_dict.get('order_time')
            self.trans_time = response_dict.get('trans_time')
            self.pay_time = response_dict.get('pay_time')
            self.term_no = response_dict.get('term_no')
            self.device_no = response_dict.get('device_no')
            self.remark = response_dict.get('remark')
            self.pay_type = response_dict.get('pay_type')
            self.openid = response_dict.get('openid')
            self.final_amount = response_dict.get('final_amount')


class PreOrderRequest(OrgBaseReq):
    """预下单请求"""
    
    API_PREFIX = "/open/cashier/trans/trade"
    API_URI = "/pre-order"
    
    def __init__(self):
        """初始化预下单请求"""
        super().__init__()
        self.term_no = None
        self.out_trade_no = None
        self.payment_valid_time = None
        self.description = None
        self.attach = None
        self.total_amount = None
        self.remark = None
        self.notify_url = None
        self.env_version = None
        self.merch_appid = None
        self.return_url = None
    
    def set_merch_no(self, merch_no):
        """
        设置商户号
        
        Args:
            merch_no: 商户号
            
        Returns:
            PreOrderRequest实例
        """
        self.merch_no = merch_no
        return self
    
    def set_term_no(self, term_no):
        """
        设置终端号
        
        Args:
            term_no: 终端号
            
        Returns:
            PreOrderRequest实例
        """
        self.term_no = term_no
        return self
    
    def set_out_trade_no(self, out_trade_no):
        """
        设置外部交易号
        
        Args:
            out_trade_no: 外部交易号
            
        Returns:
            PreOrderRequest实例
        """
        self.out_trade_no = out_trade_no
        return self
    
    def set_payment_valid_time(self, payment_valid_time):
        """
        设置支付有效期
        
        Args:
            payment_valid_time: 支付有效期
            
        Returns:
            PreOrderRequest实例
        """
        self.payment_valid_time = payment_valid_time
        return self
    
    def set_description(self, description):
        """
        设置商品描述
        
        Args:
            description: 商品描述
            
        Returns:
            PreOrderRequest实例
        """
        self.description = description
        return self
    
    def set_attach(self, attach):
        """
        设置附加数据
        
        Args:
            attach: 附加数据
            
        Returns:
            PreOrderRequest实例
        """
        self.attach = attach
        return self
    
    def set_total_amount(self, total_amount):
        """
        设置总金额
        
        Args:
            total_amount: 总金额
            
        Returns:
            PreOrderRequest实例
        """
        self.total_amount = total_amount
        return self
    
    def set_remark(self, remark):
        """
        设置备注
        
        Args:
            remark: 备注
            
        Returns:
            PreOrderRequest实例
        """
        self.remark = remark
        return self
    
    def set_notify_url(self, notify_url):
        """
        设置通知地址
        
        Args:
            notify_url: 通知地址
            
        Returns:
            PreOrderRequest实例
        """
        self.notify_url = notify_url
        return self
    
    def set_env_version(self, env_version):
        """
        设置环境版本
        
        Args:
            env_version: 环境版本
            
        Returns:
            PreOrderRequest实例
        """
        self.env_version = env_version
        return self
    
    def set_merch_appid(self, merch_appid):
        """
        设置商户应用ID
        
        Args:
            merch_appid: 商户应用ID
            
        Returns:
            PreOrderRequest实例
        """
        self.merch_appid = merch_appid
        return self
    
    def set_return_url(self, return_url):
        """
        设置返回地址
        
        Args:
            return_url: 返回地址
            
        Returns:
            PreOrderRequest实例
        """
        self.return_url = return_url
        return self


class PreOrderResponse(BaseResponse):
    """预下单响应"""
    
    def __init__(self, response_dict=None):
        """
        初始化预下单响应
        
        Args:
            response_dict: 响应字典
        """
        super().__init__(response_dict)
        self.jl_pay_appid = None
        self.gh_id = None
        self.cashier_url = None
        
        if response_dict:
            self.jl_pay_appid = response_dict.get('jl_pay_appid')
            self.gh_id = response_dict.get('gh_id')
            self.cashier_url = response_dict.get('cashier_url')


class TradeCancelRequest(OrgBaseReq):
    """交易撤销请求"""
    
    API_PREFIX = "/open/cashier/trans/trade"
    API_URI = "/cancel"
    
    def __init__(self):
        """初始化交易撤销请求"""
        super().__init__()
        self.out_trade_no = None
        self.ori_out_trade_no = None
        self.remark = None
    
    def set_merch_no(self, merch_no):
        """
        设置商户号
        
        Args:
            merch_no: 商户号
            
        Returns:
            TradeCancelRequest实例
        """
        self.merch_no = merch_no
        return self
    
    def set_out_trade_no(self, out_trade_no):
        """
        设置外部交易号
        
        Args:
            out_trade_no: 外部交易号
            
        Returns:
            TradeCancelRequest实例
        """
        self.out_trade_no = out_trade_no
        return self
    
    def set_ori_out_trade_no(self, ori_out_trade_no):
        """
        设置原外部交易号
        
        Args:
            ori_out_trade_no: 原外部交易号
            
        Returns:
            TradeCancelRequest实例
        """
        self.ori_out_trade_no = ori_out_trade_no
        return self
    
    def set_remark(self, remark):
        """
        设置备注信息
        
        Args:
            remark: 备注信息
            
        Returns:
            TradeCancelRequest实例
        """
        self.remark = remark
        return self


class TradeCancelResponse(BaseResponse):
    """交易撤销响应"""
    
    def __init__(self, response_dict=None):
        """
        初始化交易撤销响应
        
        Args:
            response_dict: 响应字典
        """
        super().__init__(response_dict)
        self.status = None
        self.merch_no = None
        self.transaction_id = None
        self.out_trade_no = None
        self.ori_out_trade_no = None
        self.ori_transaction_id = None
        self.order_time = None
        self.pay_type = None
        self.total_amount = None
        self.trans_time = None
        
        if response_dict:
            self.status = response_dict.get('status')
            self.merch_no = response_dict.get('merch_no')
            self.transaction_id = response_dict.get('transaction_id')
            self.out_trade_no = response_dict.get('out_trade_no')
            self.ori_out_trade_no = response_dict.get('ori_out_trade_no')
            self.ori_transaction_id = response_dict.get('ori_transaction_id')
            self.order_time = response_dict.get('order_time')
            self.pay_type = response_dict.get('pay_type')
            self.total_amount = response_dict.get('total_amount')
            self.trans_time = response_dict.get('trans_time')


class TradeRefundRequest(OrgBaseReq):
    """交易退款请求"""
    
    API_PREFIX = "/open/cashier/trans/trade"
    API_URI = "/refund"
    
    def __init__(self):
        """初始化交易退款请求"""
        super().__init__()
        self.out_trade_no = None
        self.ori_out_trade_no = None
        self.total_amount = None
        self.remark = None
    
    def set_merch_no(self, merch_no):
        """
        设置商户号
        
        Args:
            merch_no: 商户号
            
        Returns:
            TradeRefundRequest实例
        """
        self.merch_no = merch_no
        return self
    
    def set_out_trade_no(self, out_trade_no):
        """
        设置外部交易号
        
        Args:
            out_trade_no: 外部交易号
            
        Returns:
            TradeRefundRequest实例
        """
        self.out_trade_no = out_trade_no
        return self
    
    def set_ori_out_trade_no(self, ori_out_trade_no):
        """
        设置原外部交易号
        
        Args:
            ori_out_trade_no: 原外部交易号
            
        Returns:
            TradeRefundRequest实例
        """
        self.ori_out_trade_no = ori_out_trade_no
        return self
    
    def set_total_amount(self, total_amount):
        """
        设置退款金额
        
        Args:
            total_amount: 退款金额
            
        Returns:
            TradeRefundRequest实例
        """
        self.total_amount = total_amount
        return self
    
    def set_remark(self, remark):
        """
        设置备注信息
        
        Args:
            remark: 备注信息
            
        Returns:
            TradeRefundRequest实例
        """
        self.remark = remark
        return self


class TradeRefundResponse(BaseResponse):
    """交易退款响应"""
    
    def __init__(self, response_dict=None):
        """
        初始化交易退款响应
        
        Args:
            response_dict: 响应字典
        """
        super().__init__(response_dict)
        self.status = None
        self.merch_no = None
        self.transaction_id = None
        self.out_trade_no = None
        self.chn_transaction_id = None
        self.ori_out_trade_no = None
        self.ori_transaction_id = None
        self.total_amount = None
        self.order_time = None
        self.trans_time = None
        self.pay_type = None
        
        if response_dict:
            self.status = response_dict.get('status')
            self.merch_no = response_dict.get('merch_no')
            self.transaction_id = response_dict.get('transaction_id')
            self.out_trade_no = response_dict.get('out_trade_no')
            self.chn_transaction_id = response_dict.get('chn_transaction_id')
            self.ori_out_trade_no = response_dict.get('ori_out_trade_no')
            self.ori_transaction_id = response_dict.get('ori_transaction_id')
            self.total_amount = response_dict.get('total_amount')
            self.order_time = response_dict.get('order_time')
            self.trans_time = response_dict.get('trans_time')
            self.pay_type = response_dict.get('pay_type') 